//
//  MaintainSaveViewController.m
//  StationManager
//
//  Created by 张佳强 on 17/3/15.
//  Copyright © 2017年 Helong. All rights reserved.
//

#import "MaintainSaveViewController.h"
#import "DocumentCell.h"
#import "UserInfoModel.h"
#import <Masonry.h>
#import "SavedStationCell.h"
#import <MBProgressHUD.h>
#import <AFNetworking.h>

#define BLUECOLOR [UIColor colorWithRed:34/255.0 green:150/255.0 blue:243/255.0 alpha:1.0]

@interface MaintainSaveViewController ()<UITableViewDelegate,UITableViewDataSource,SavedStationDelegate,UploadStationDelegate,UIScrollViewDelegate>
@property (nonatomic , strong) UIButton *unuploadButton;
@property (nonatomic , strong) UIButton *uploadButton;
@property (nonatomic , strong) UIView *line;
//背景View
@property (strong,nonatomic) UIView * bgView;
//底部View
@property (nonatomic,strong) UIView * bottomView;
//按钮背景Label
@property (nonatomic,strong) UILabel * selectLabel;
//提交按钮Button
@property (nonatomic,strong) UIButton * submitButton;
//删除按钮Button
@property (nonatomic,strong) UIButton * deleteButton;
@property (nonatomic,strong) UIButton * deleteButton2;
//全选按钮Button
@property (nonatomic,strong) UIButton * selectButton;
//文件名Label
@property (nonatomic,strong) UILabel * documentLabel;
//文件数据列表TableView
//@property (nonatomic,strong) UITableView * tableView;
//列表数据源
//@property (nonatomic,strong) NSMutableArray * dataArray;
//上传文件的进度条
@property (strong,nonatomic) UIProgressView * progressView;
//存储删除文件的字典
@property (nonatomic,strong) NSMutableDictionary * deleteDict;
//存储提交文件的字典
@property (nonatomic,strong) NSMutableDictionary * submitDict;
@property (strong,nonatomic) MBProgressHUD * hud;

@property (nonatomic , strong) UIScrollView *scrollView;
@property (nonatomic , strong) UITableView *unuploadTableView;
@property (nonatomic , strong) UITableView *uploadTableView;
@property (nonatomic , strong) NSMutableArray *unuploadDataArray;
@property (nonatomic , strong) NSMutableArray *uploadDataArray;


@end

@implementation MaintainSaveViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.title = @"已保存的维护日志";
    
    _unuploadDataArray = [NSMutableArray arrayWithCapacity:0];
    _uploadDataArray = [NSMutableArray arrayWithCapacity:0];
    _deleteDict = [[NSMutableDictionary alloc]initWithCapacity:0];
    _submitDict = [[NSMutableDictionary alloc]initWithCapacity:0];
    NSString *strFinalPath=[NSString stringWithFormat:@"%@/Documents/taizhan",NSHomeDirectory()];
    NSArray *fileList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:strFinalPath error:nil];
    for (NSString * documentName in fileList) {
        if (documentName.length>14) {
            
            [_unuploadDataArray addObject:documentName];
        }
    }
    
    NSString *savedFinalPath=[NSString stringWithFormat:@"%@/Documents/taizhansaved",NSHomeDirectory()];
    NSLog(@"%@",savedFinalPath);
    NSArray *fileList2 = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:savedFinalPath error:nil];
    for (NSString * documentName in fileList2) {
        if (documentName.length>14) {
            
            [_uploadDataArray addObject:documentName];
        }
    }
    
    [self setUI];
    

//    [self setUI];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(submited:) name:@"submited" object:nil];
}

//设置UI
-(void)setUI{
    
    _unuploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_unuploadButton setTitle:@"未上传" forState:UIControlStateNormal];
    [_unuploadButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_unuploadButton setTitleColor:BLUECOLOR forState:UIControlStateSelected];
    _unuploadButton.titleLabel.font = [UIFont systemFontOfSize:13];
    _unuploadButton.selected = YES;
    [_unuploadButton addTarget:self action:@selector(unuploadClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_unuploadButton];
    
    [_unuploadButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.equalTo(@0);
        make.width.mas_equalTo(SCREEN_WIDTH/2);
        make.height.mas_equalTo(40);
    }];
    
    _uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_uploadButton setTitle:@"已上传" forState:UIControlStateNormal];
    [_uploadButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_uploadButton setTitleColor:BLUECOLOR forState:UIControlStateSelected];
    _uploadButton.titleLabel.font = [UIFont systemFontOfSize:13];
    _uploadButton.selected = NO;
    [_uploadButton addTarget:self action:@selector(uploadClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_uploadButton];
    
    [_uploadButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.top.equalTo(@0);
        make.width.mas_equalTo(SCREEN_WIDTH/2);
        make.height.mas_equalTo(40);
    }];
    
    _line = [[UIView alloc] initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH/2, 2)];
    _line.backgroundColor = BLUECOLOR;
    [self.view addSubview:_line];
    
    
    _scrollView = [[UIScrollView alloc] init];
    _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH*2, SCREEN_HEIGHT-110);
    
    _scrollView.bounces = YES;
    _scrollView.pagingEnabled = YES;
    _scrollView.delegate = self;
    _scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
    
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(@0);
        make.top.equalTo(_line.mas_bottom);
        make.bottom.equalTo(@0);
    }];
    
    _unuploadTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.view.bounds.size.height-82) style:UITableViewStylePlain];
    _unuploadTableView.delegate = self;
    _unuploadTableView.dataSource = self;
    _unuploadTableView.showsVerticalScrollIndicator = NO;
    _unuploadTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [_scrollView addSubview:_unuploadTableView];
    
    _uploadTableView = [[UITableView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, self.view.bounds.size.height-82) style:UITableViewStylePlain];
    _uploadTableView.showsVerticalScrollIndicator = NO;
    
    _uploadTableView.delegate = self;
    _uploadTableView.dataSource = self;
    _uploadTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    
    [_scrollView addSubview:_uploadTableView];
    
    UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-144, SCREEN_WIDTH, 40)];
    bottomView.backgroundColor = [UIColor colorWithRed:34/255.0 green:150/255.0 blue:243/255.0 alpha:1.0];
    [_scrollView addSubview:bottomView];
    
    //    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
    //
    //        make.left.right.bottom.equalTo(@0);
    //        make.height.mas_equalTo(40);
    //    }];
    
    _submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_submitButton setTitle:@"提交" forState:UIControlStateNormal];
    [_submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _submitButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [_submitButton addTarget:self action:@selector(submitClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:_submitButton];
    
    _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_deleteButton setTitle:@"删除" forState:UIControlStateNormal];
    [_deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _deleteButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [_deleteButton addTarget:self action:@selector(deleteClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:_deleteButton];
    
    [_submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@20);
        make.top.equalTo(@5);
        make.bottom.equalTo(@-5);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(30);
    }];
    
    [_deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-20);
        make.top.equalTo(@5);
        make.bottom.equalTo(@-5);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(30);
    }];
    
    
    UIView *bottomView2 = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH, SCREEN_HEIGHT-144, SCREEN_WIDTH, 40)];
    bottomView2.backgroundColor = [UIColor colorWithRed:34/255.0 green:150/255.0 blue:243/255.0 alpha:1.0];
    [_scrollView addSubview:bottomView2];
    
    _deleteButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [_deleteButton2 setTitle:@"删除" forState:UIControlStateNormal];
    [_deleteButton2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _deleteButton2.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [_deleteButton2 addTarget:self action:@selector(uploadDeleteClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView2 addSubview:_deleteButton2];
    
    [_deleteButton2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-20);
        make.top.equalTo(@5);
        make.bottom.equalTo(@-5);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(30);
    }];
}


#pragma mark Notification - Delegate



//点击提交按钮
- (void)submitClick {
    
    
    if (_deleteDict.count == 0) {
        
        [self showAlert:@"请选择文件" duration:1.0 IsSubmited:NO];
    }
    else{
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor blackColor];
        _bgView.alpha = 0.8;
        [self.view addSubview:_bgView];
        
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@50);
            make.top.equalTo(@(SCREEN_HEIGHT/3));
            make.right.equalTo(@-50);
            make.height.mas_equalTo(50);
        }];
        
        _progressView = [[UIProgressView alloc]init];
        _progressView.progress=0.0;
        [_bgView addSubview:_progressView];
        
        [_progressView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@5);
            make.top.equalTo(@5);
            make.right.equalTo(@-5);
            make.height.mas_equalTo(10);
        }];
        
        UILabel * foldSizeLabel = [[UILabel alloc]init];
        foldSizeLabel.backgroundColor = [UIColor blackColor];
        foldSizeLabel.font = [UIFont systemFontOfSize:11.0];
        foldSizeLabel.textAlignment = NSTextAlignmentCenter;
        foldSizeLabel.textColor = [UIColor whiteColor];
        [_bgView addSubview:foldSizeLabel];
        
        UILabel * uploadSizeLabel = [[UILabel alloc]init];
        uploadSizeLabel.backgroundColor = [UIColor blackColor];
        uploadSizeLabel.font = [UIFont systemFontOfSize:11.0];
        uploadSizeLabel.textAlignment = NSTextAlignmentCenter;
        uploadSizeLabel.textColor = [UIColor whiteColor];
        [_bgView addSubview:uploadSizeLabel];
        
        [foldSizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@-5);
            make.top.equalTo(_progressView.mas_bottom).offset(5);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(20);
        }];
        
        [uploadSizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@5);
            make.top.equalTo(_progressView.mas_bottom).offset(5);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(20);
        }];
        
        NSString *strPath=[NSString stringWithFormat:@"%@/Documents/taizhan",NSHomeDirectory()];
        NSMutableArray *txtDocuments = [[NSMutableArray alloc] initWithCapacity:0];
        NSMutableArray *zipDocuments = [[NSMutableArray alloc] initWithCapacity:0];
        NSMutableArray *foldDocuments = [[NSMutableArray alloc] initWithCapacity:0];
        
        for (NSString * values in [_deleteDict allValues]) {
            NSString * foldName = @"";
            if ([values hasPrefix:@"（已提交）"]) {
                foldName = [values substringFromIndex:5];
                [foldDocuments addObject:foldName];
            }else{
                foldName = values;
                [foldDocuments addObject:foldName];
                
            }
            NSArray *fileList  = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@/%@",strPath,foldName] error:nil];
            NSLog(@"%lu",(unsigned long)fileList.count);
            for (NSString * documents in fileList) {
                if ([documents hasSuffix:@".txt"]) {
                    
                    [txtDocuments addObject:documents];
                }
                if ([documents hasSuffix:@".zip"]) {
                    [zipDocuments addObject:documents];
                }
            }
        }
        
        AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                             @"text/html",
                                                             @"image/jpeg",
                                                             @"image/png",
                                                             @"application/octet-stream",
                                                             @"text/json",
                                                             @"text/plain",
                                                             @"video/mp4",
                                                             @"application/gzip",
                                                             nil];
        
        for (NSInteger i = 0; i<foldDocuments.count; i++) {
            foldSizeLabel.text = [NSString stringWithFormat:@"总共：%.2fM",[self folderSizeAtPath:[NSString stringWithFormat:@"%@/%@",strPath,foldDocuments[i]]]];
            NSURLSessionDataTask *task = [manager POST:@"http://192.168.0.77:8080/Phone/upload.aspx" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
                
                [formData appendPartWithFileData:[NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/%@",strPath,foldDocuments[i],txtDocuments[i]]] name:@"file_txt" fileName:txtDocuments[i] mimeType:@"text/plain"];
                
                [formData appendPartWithFileData:[NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/%@",strPath,foldDocuments[i],zipDocuments[i]]] name:@"file_pic" fileName:zipDocuments[i] mimeType:@"application/gzip"];
                
            } progress:^(NSProgress *_Nonnull uploadProgress) {
                //打印下上传进度
                NSLog(@"%lf",1.0 *uploadProgress.completedUnitCount / uploadProgress.totalUnitCount);
                
                dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                dispatch_async(queue, ^{
                    CGFloat value = 1.0 *uploadProgress.completedUnitCount / uploadProgress.totalUnitCount;
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        uploadSizeLabel.text = [NSString stringWithFormat:@"已上传：%.2fM",value*[self folderSizeAtPath:[NSString stringWithFormat:@"%@/%@",strPath,foldDocuments[i]]]];
                        [_progressView setProgress:value animated:YES];
                    });
                });
                
            } success:^(NSURLSessionDataTask *_Nonnull task, id _Nullable responseObject) {
                //上传成功
                [_progressView removeFromSuperview];
                [_bgView removeFromSuperview];
//                _selectButton.selected = NO;
                
                NSString *strPath=[NSString stringWithFormat:@"%@/Documents/taizhan",NSHomeDirectory()];
                
                NSString *savestrPath=[NSString stringWithFormat:@"%@/Documents/taizhansaved",NSHomeDirectory()];
                NSLog(@"savePath:%@",savestrPath);
                  [[NSFileManager defaultManager] createDirectoryAtPath:savestrPath withIntermediateDirectories:YES attributes:nil error:nil];
                for (NSString * value in [_deleteDict allValues]) {
                    [[NSFileManager defaultManager] copyItemAtPath:[NSString stringWithFormat:@"%@/%@",strPath,value] toPath:[NSString stringWithFormat:@"%@/%@",savestrPath,value] error:nil];
                    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@",strPath,value] error:nil];
                    [_uploadDataArray addObject:value];
                    [_unuploadDataArray removeObject:value];
                }
                [_deleteDict removeAllObjects];
                [_uploadTableView reloadData];
                [_unuploadTableView reloadData];

                
            } failure:^(NSURLSessionDataTask *_Nullable task, NSError * _Nonnull error) {
                //请求失败
                NSLog(@"上传失败：%@",error);
                
            }];
            
            [task resume];
        }
 
        
    }
}

//点击删除按钮
- (void)deleteClick {
    
    if (_deleteDict.count == 0) {
        
        [self showAlert:@"请选择文件" duration:1.0 IsSubmited:NO];
    }
    else{
        NSString *strPath=[NSString stringWithFormat:@"%@/Documents/taizhan",NSHomeDirectory()];
        for (NSString * value in [_deleteDict allValues]) {
            
            [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@",strPath,value] error:nil];
            
            [_unuploadDataArray removeObject:value];
        }
        [_deleteDict removeAllObjects];
        [_unuploadTableView reloadData];
    }

}

//获取单个文件的大小
- (long long)fileSizeAtPath:(NSString*)filePath {
    
    NSFileManager* manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:filePath]){
        
        return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
    }
    return 0;
}

//获取整个文件夹的大小
- (float )folderSizeAtPath:(NSString*)folderPath {
    
    NSFileManager* manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:folderPath]) return 0;
    NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
    NSString* fileName;
    long long folderSize = 0;
    while ((fileName = [childFilesEnumerator nextObject]) != nil){
        
        NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
        folderSize += [self fileSizeAtPath:fileAbsolutePath];
        
    }
    return folderSize/(1024.0*1024.0);
    
}

-(void)uploadDeleteClick{
    
    
    if (_submitDict.count == 0) {
        
        [self showAlert:@"请选择文件" duration:1.0 IsSubmited:NO];
    }
    else{
        NSString *strPath=[NSString stringWithFormat:@"%@/Documents/taizhansaved",NSHomeDirectory()];
        for (NSString * value in [_submitDict allValues]) {
            
            [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@",strPath,value] error:nil];
            
            [_uploadDataArray removeObject:value];
        }
        [_submitDict removeAllObjects];
        [_uploadTableView reloadData];
    }
    
}
-(void)unuploadClick{
    
    _unuploadButton.selected = YES;
    _uploadButton.selected = NO;
    
    [UIView animateWithDuration:0.5 animations:^{
         self.scrollView.contentOffset = CGPointMake(0, 0);
        _line.frame = CGRectMake(0, 40, SCREEN_WIDTH/2, 2);
    }];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    int i = scrollView.contentOffset.x/SCREEN_WIDTH;
    if (i == 0) {
        _unuploadButton.selected = YES;
        _uploadButton.selected = NO;
        [UIView animateWithDuration:0.1 animations:^{
            self.scrollView.contentOffset = CGPointMake(0, 0);

            _line.frame = CGRectMake(0, 37, SCREEN_WIDTH/2, 3);
        }];
        
    }else{
        _unuploadButton.selected = NO;
        _uploadButton.selected = YES;
        
        [UIView animateWithDuration:0.1 animations:^{
            self.scrollView.contentOffset = CGPointMake(SCREEN_WIDTH, 0);

            _line.frame = CGRectMake(SCREEN_WIDTH/2, 37, SCREEN_WIDTH/2, 3);
        }];
    }
}
-(void)uploadClick{
    
    _unuploadButton.selected = NO;
    _uploadButton.selected = YES;
    
    [UIView animateWithDuration:0.5 animations:^{
         self.scrollView.contentOffset = CGPointMake(SCREEN_WIDTH, 0);
        _line.frame = CGRectMake(SCREEN_WIDTH/2, 40, SCREEN_WIDTH/2, 2);
    }];
    
}

////点击全选按钮
//- (void)selectClick {
//    
//    if (_selectButton.selected) {
//        
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"unselected" object:nil];
//        _selectButton.selected = NO;
//        [_tableView reloadData];
//    }else{
//        
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"selected" object:nil];
//        _selectButton.selected = YES;
//        [_tableView reloadData];
//    }
//}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (tableView == _unuploadTableView) {
        
        return _unuploadDataArray.count;
    }else{
        return _uploadDataArray.count;
        
    }
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView == _unuploadTableView) {
        
        static NSString *iden = @"unuploadCell";
        SavedStationCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
        if (cell == nil) {
            cell = [[SavedStationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
        }
        cell.cellTag = indexPath.row;
        cell.type = @"unupload";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.selectButton.selected = NO;
        cell.savedStationDelegate = self;
        cell.nameLabel.text = [NSString stringWithFormat:@"%@.txt",_unuploadDataArray[indexPath.row]];
        return cell;
    }
    else{
        static NSString *iden = @"uploadCell";
        SavedStationCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
        if (cell == nil) {
            cell = [[SavedStationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
        }
        cell.cellTag = indexPath.row;
        cell.type = @"upload";
        cell.selectButton.selected = NO;
        cell.uploadStationDelegate = self;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.nameLabel.text =[NSString stringWithFormat:@"(已上传)%@.txt",_uploadDataArray[indexPath.row]];;
        return cell;
    }
}




-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 30;
}


//将所要删除的cell数据添加到字典中
- (void)sendDocumentName:(NSInteger)celltag {
    
    [_deleteDict setValue:_unuploadDataArray[celltag] forKey:[NSString stringWithFormat:@"%zi",celltag]];
}

//将取消删除的cell从字典中移除
- (void)removeDocumentname:(NSInteger)celltag {
    
    [_deleteDict removeObjectForKey:[NSString stringWithFormat:@"%zi",celltag]];
}


-(void)senduploadDocumentName:(NSInteger)celltag{
    
    [_submitDict setValue:_uploadDataArray[celltag] forKey:[NSString stringWithFormat:@"%zi",celltag]];
    
}


-(void)removeuploadDocumentname:(NSInteger)celltag{
    
    [_submitDict removeObjectForKey:[NSString stringWithFormat:@"%zi",celltag]];
}

//弹出提示框
- (void)showAlert:(NSString *)message duration:(CGFloat)duration IsSubmited:(BOOL)isSubmited {
    
    _hud = [[MBProgressHUD alloc] init];
    _hud.center = CGPointMake(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
    [[UIApplication sharedApplication].keyWindow addSubview:_hud];
    _hud.animationType =MBProgressHUDAnimationZoom;
    _hud.mode = MBProgressHUDModeText;
    _hud.label.text = message;
    _hud.label.numberOfLines = 0;
    _hud.label.font = [UIFont systemFontOfSize:12];
    _hud.removeFromSuperViewOnHide = YES;
    [_hud showAnimated:NO];
    [_hud hideAnimated:YES afterDelay:duration];
    if (isSubmited) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
